﻿<%@ WebHandler Language="C#" Class="Training.Web.AjaxHandler.Loaddata.Administration.Catalog.KaryawanLoadHandler" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Text;

using Training.Library.DataAccess.Administration;
using Training.Library.DomainObject.Administration;
using Training.Library.DataAccess.Administration.Catalog;
using Training.Library.DomainObject.Administration.Catalog;

using Training.Library.Enum;
using Assesment.Web.Support;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;

using Newtonsoft.Json.Linq;

namespace Training.Web.AjaxHandler.Loaddata.Administration.Catalog
{

    public class KaryawanLoadHandler : Assesment.Web.BaseHandler
    {

        KaryawanRepo KaryawanDal = new KaryawanRepo(ConfigurationManager.ConnectionStrings["TrainingConn"].ConnectionString);
        string MethodName = string.Empty;
        private Assesment.Library.DataAccess.Administration.recLogRepo logDal = new Assesment.Library.DataAccess.Administration.recLogRepo(ConfigurationManager.ConnectionStrings["AssesmentConn"].ConnectionString);

        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);

            StringBuilder sbProject = new StringBuilder();
            if (context.Request.Params["method"] != null)
                MethodName = context.Request.Params["method"];

            try
            {
                if (MethodName == "getbyid")
                {
                    string NIK = context.Request.Params["NIK"].ToString();

                    Karyawan objKaryawan = KaryawanDal.GetById(NIK);

                    PositionRepo PositionDal = new PositionRepo(ConfigurationManager.ConnectionStrings["JobdescConn"].ConnectionString);
                    Position objPosition = PositionDal.GetById(Convert.ToInt32(objKaryawan.PositionID));

                    DepartmentRepo DepartmentDal = new DepartmentRepo(ConfigurationManager.ConnectionStrings["JobdescConn"].ConnectionString);
                    Department objDept = DepartmentDal.GetById(Convert.ToInt32(objPosition.DepartmentID));

                    CabangRepo CabangDal = new CabangRepo(ConfigurationManager.ConnectionStrings["TrainingConn"].ConnectionString);
                    Cabang objCabang = CabangDal.GetById(Convert.ToInt32(objKaryawan.CabangID));

                    LokasiRepo LokasiDal = new LokasiRepo(ConfigurationManager.ConnectionStrings["TrainingConn"].ConnectionString);
                    Lokasi objLokasi = LokasiDal.GetById(Convert.ToInt32(objKaryawan.LokasiID));


                    sbProject.Append("{");
                    sbProject.AppendFormat("  {0}NamaKaryawan{0}:{0}{1}{0}", "\"", objKaryawan.NamaKaryawan);
                    sbProject.Append(",");
                    sbProject.AppendFormat("  {0}Jabatan{0}:{0}{1}{0}", "\"", objPosition.PositionName);
                    sbProject.Append(",");
                    sbProject.AppendFormat("  {0}Lokasi{0}:{0}{1}{0}", "\"", objLokasi.NamaLokasi);
                    sbProject.Append("}");
                    context.Response.Write(sbProject.ToString());


                }
            }
            catch ( Exception ex)
            {
                Assesment.Library.DomainObject.Administration.recLog log = new Assesment.Library.DomainObject.Administration.recLog();
                log.LogEvent = "load getbyid";
                log.LogMessage = ex.Message;
                //log.SourceSP = "SP_Competency_Insert";
                log.LogSource = "KaryawanLoad.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }

           
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}